# This controller handles the login/logout function of the site.
class SessionsController < ApplicationController

  # render new.rhtml
  def new
     self.current_user = User.authenticate(params[:login], params[:password])

    if current_user
      #if params[:remember_me] == "1"
      #  current_user.remember_me unless current_user.remember_token?
      #  cookies[:auth_token] = { :value => self.current_user.remember_token , :expires => self.current_user.remember_token_expires_at }
      #end
      redirect_back_or_default(root_path)
      flash[:notice] = "Você está logado"
    else
      flash[:notice] = "Login ou password incorreto(s)" unless (params[:login].blank? and params[:password].blank?) #gambi
      render :action => 'new'
    end
  end

  def create
  end

  def destroy
    self.current_user.forget_me if logged_in?
    cookies.delete :auth_token
    reset_session
    flash[:notice] = "Você foi Deslogado"
    redirect_back_or_default('/')
  end
end

